<template>
	<div class="port-page">

		<!--<div class="but1">
		<router-link to="/home">
			<el-button type="warning" size="small"  class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
		</router-link>
	    </div>-->
		<el-tabs v-model="activeName" type="card" @tab-click='tabchk'>
			<el-tab-pane label="采购入库" name="cgrk"></el-tab-pane>
			<el-tab-pane label="库存查询" name="kccx"></el-tab-pane>
			<el-tab-pane label="老师领用" name="lyck"></el-tab-pane>
			<el-tab-pane label="报损" name="bs"></el-tab-pane>
			<el-tab-pane label="采购退货" name="cgth"></el-tab-pane>
			<el-tab-pane label="盘点" name="pd"></el-tab-pane>
			<el-tab-pane label="进出库查询" name="jckcx"></el-tab-pane>
		</el-tabs>

		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- 采购入库 -->
		<CgrkComponent v-if="portComponents.cgrk.toggle" @close="componentsHide" :params="portComponents.cgrk.params"></CgrkComponent>
		<!-- 库存查询 -->
		<KccxComponent v-if="portComponents.kccx.toggle" @close="componentsHide" :params="portComponents.kccx.params"></KccxComponent>
        <!-- 领用出库 -->
		<LyckComponent v-if="portComponents.lyck.toggle" @close="componentsHide" :params="portComponents.lyck.params"></LyckComponent>
		<!-- 报损 -->
		<BsComponent v-if="portComponents.bs.toggle" @close="componentsHide" :params="portComponents.bs.params"></BsComponent>
		<!-- 采购退货 -->
		<CgthComponent v-if="portComponents.cgth.toggle" @close="componentsHide" :params="portComponents.cgth.params"></CgthComponent>
		<!-- 盘点 -->
		<PdComponent   v-if="portComponents.pd.toggle"   @close="componentsHide" :params="portComponents.pd.params"></PdComponent>
		<!-- 进出库查询 -->
		<JckcxComponent v-if="portComponents.jckcx.toggle" @close="componentsHide" :params="portComponents.jckcx.params"></JckcxComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"> </router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import CgrkComponent from 'view/manage/cgrk/list'
	import KccxComponent from 'view/manage/kccx/list'
	import LyckComponent from 'view/manage/lyck/list'
	import BsComponent from 'view/manage/bs/list'
	import CgthComponent from 'view/manage/cgth/list'
	import PdComponent from 'view/manage/pd/list'
	import JckcxComponent from 'view/manage/jckcx/list'
	import qs from 'qs'
	export default {
		props: ['params'],
		components: {LoadingComponent,CgrkComponent,KccxComponent,LyckComponent,BsComponent,CgthComponent,PdComponent,JckcxComponent},
		data() {
			return {
				activeName: 'cgrk',

				/*模糊搜索条件*/
				wpfl:'' ,
				vcnt1: '',
				vcnt2: '',
				vsfsj: 'Y',
				vkeyword: '', // 关键字
				vflmc: '',
				vwpflid: '',
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 单行删除  */
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该记录?, 是否继续?'
						}
					},
					/* 批量删除 */
					multipleDelete: {
						type: 'multipleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'multiple',
							title: '此操作将删除您选中的记录?, 是否继续?'
						}
					},
					//采购入库
					cgrk: {
						type: 'cgrk',
						toggle: false,
						params: '',
						data: {}
					},
					//库存查询
					kccx: {
						type: 'kccx',
						toggle: false,
						params: '',
						data: {}
					},
					//领用出库
					lyck: {
						type: 'lyck',
						toggle: false,
						params: '',
						data: {}
					},
					//报修
					bx: {
						type: 'bx',
						toggle: false,
						params: '',
						data: {}
					},
					//报损
					bs: {
						type: 'bs',
						toggle: false,
						params: '',
						data: {}
					},
					//采购退货
					cgth: {
						type: 'cgth',
						toggle: false,
						params: '',
						data: {}
					},
					//盘点
					pd: {
						type: 'pd',
						toggle: false,
						params: '',
						data: {}
					},
					//进出库查询
					jckcx: {
						type: 'jckcx',
						toggle: false,
						params: '',
						data: {}
					},
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [

					{
						prop: 'id',
						label: '主键',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xxid',
						label: '学校id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xxmc',
						label: '学校名称',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'ckid',
						label: '仓库id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'flmc',
						label: '物品分类',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpid',
						label: '物品id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'cnt',
						label: '库存数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'jccnt',
						label: '领用数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'zzbxsl',
						label: '报修数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'yxhsl',
						label: '已修好数量',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'bssl',
						label: '报损数量',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					}

				]
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', '办公用品类进销存'); //修改title
			this.$store.dispatch('changeRouterIndex', '/manage/bgypjxcgl'); //修改路由
			this.search(); //分页获取默认数据
//			this.getcomboxlist(); //加载下拉列表
			this.isLoading = true; //动画开始
			var arr = {name:"cgrk"}
			this.tabchk(arr)
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			tabchk(tab) {
				this.portComponents.cgrk.toggle = false;
				this.portComponents.kccx.toggle = false;
				this.portComponents.lyck.toggle = false;
				this.portComponents.bs.toggle = false;
				this.portComponents.cgth.toggle = false;
				this.portComponents.pd.toggle = false;
				this.portComponents.jckcx.toggle = false;
				

				if(tab.name == 'cgrk') {
					this.portComponents.cgrk.toggle = true;
					this.portComponents.cgrk.params = '4';
				} 
				else if(tab.name == 'kccx') {
					this.portComponents.kccx.toggle = true;
					this.portComponents.kccx.params = '4';
				}
				else if(tab.name == 'lyck') {
					this.portComponents.lyck.toggle = true;
					this.portComponents.lyck.params = '4';
				}
				else if(tab.name == 'bs') {
					this.portComponents.bs.toggle = true;
					this.portComponents.bs.params = '4';
				}
				else if(tab.name == 'cgth') {
					this.portComponents.cgth.toggle = true;
					this.portComponents.cgth.params = '4';
				}
				else if(tab.name == 'pd') {
					this.portComponents.pd.toggle = true;
					this.portComponents.pd.params = '4';
				}
				else if(tab.name == 'jckcx') {
					this.portComponents.jckcx.toggle = true;
					this.portComponents.jckcx.params = '4';
				}
				else {
					this.componentsShow(tab.name, '')
				}
			},
			
			
			
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					keyword: this.vkeyword, // keyword
					wpflid: this.vwpflid, // 物品分类id
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'wpfl/getlist', params3)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {
						this.searchLoading = false;
					})
			},

			search() {
				//查询搜索触发事件
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					cnt1: this.vcnt1,
					cnt2: this.vcnt2,
					sfsj: this.vsfsj,
					flid: this.vwpflid,
					wpfl: this.wpfl + '',
					keyword: this.vkeyword, // 关键字
					yhid: logininfo.id,
					xxid: logininfo.xxid,
					pageindex: this.pageindex,
					pagesize: this.pagesize
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'wpkc/list', params3)
					.then(res => {
						let data = res.data.data;
						let list = data.list;
						this.total = data.totalPage;
						this.dataList = list;
						this.searchLoading = false;
					}).catch(res => {
						this.searchLoading = false;
					})
			},
			getcomlist() {
				/*  var logininfo = JSON.parse(localStorage.logininfo) ;
				  this.axios.get(this.$store.state.api + 'dome/list',{
				      params:{
				          yhid:logininfo.id,
				          xxid:logininfo.xxid
				      }
				  }).then( res => {
				      console.log(res)
				      let data = res.data.data;
				      let list = data.list;
				      this.total = data.totalPage;
				      this.dataList = list;
				      this.searchLoading = false;
				  }).catch( res => {
				  })  */
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				console.log(selection, row)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件 
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 100px;
			max-width: 135px;
		}
		.code-search1 {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 60px;
			max-width: 75px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			/*margin-right:10px;*/
		}
		.but1 {
			width: 100%;
			margin-top: 8px;
			margin-bottom: 8px;
		}
		.search {
			width: 70%;
			float: right;
			text-align: right;
		}
	}
</style>